package com.kerbores.jongo;

import java.util.List;

import org.nutz.lang.ContinueLoop;
import org.nutz.lang.Each;
import org.nutz.lang.ExitLoop;
import org.nutz.lang.Lang;
import org.nutz.lang.LoopException;

import com.kerbores.utils.collection.Lists;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;

/**
 * @author 王贵源<kerbores>
 *
 *         create at 2015年12月23日 下午3:27:08
 */
public class JongoClient extends MongoClient {

	/**
	 * @param host
	 * @param port
	 */
	public JongoClient(String host, int port) {
		super(host, port);
	}

	/**
	 * @param sas
	 * @param creds
	 * @param mopt
	 */
	public JongoClient(List<ServerAddress> sas, List<MongoCredential> creds, MongoClientOptions mopt) {
		super(sas, creds, mopt);
	}

	/**
	 * @param string
	 */
	public JongoClient(String host) {
		super(host);
	}

	public List<String> dbnames() {
		final List<String> target = Lists.newArrayList();
		Lang.each(listDatabaseNames(), new Each<String>() {

			@Override
			public void invoke(int index, String ele, int length) throws ExitLoop, ContinueLoop, LoopException {
				target.add(ele);
			}
		});
		return target;
	}

}
